#ifndef WIFI_MANAGER_H
#define WIFI_MANAGER_H

#include <WiFi.h>
#include <EEPROM.h>
#include <FastLED.h>

#define EEPROM_SIZE 256
#define CONFIG_OFFSET 96
#define CONFIG_SIZE sizeof(DeviceConfig)

struct DeviceConfig {
    uint8_t brightness;
    CRGB hourColor;
    CRGB minColor;
    CRGB secColor;
    CRGB colonColor;
    CRGB dateColor;
    CRGB weekActiveColor;
    CRGB weekInactiveColor;
};

class WiFiManager {
public:
    WiFiManager(const char* defaultSSID, const char* defaultPass);
    void begin();
    bool isConnected();
    bool isAPMode() { return apModeActive; }
    void attemptReconnect();
    void saveConfig(const DeviceConfig& config);
    void loadConfig(DeviceConfig& config);
    void resetConfig();
    const char* getSSID() { return ssid; }
    const char* getPassword() { return password; }
    
private:
    char ssid[33];
    char password[65];
    char defaultSSID[33];
    char defaultPass[65];
    bool apModeActive = false;
    unsigned long lastReconnectAttempt = 0;
    const unsigned long reconnectInterval = 30000;

    DeviceConfig defaultConfig = {
        80, 
        CRGB(0, 150, 255), 
        CRGB(50, 255, 100),
        CRGB(255, 220, 0),
        CRGB(255, 80, 80),
        CRGB(200, 0, 255),
        CRGB(0, 255, 0),
        CRGB(30, 30, 30)
    };

    void connectToWiFi(const char* ssidToConnect, const char* passToConnect);
    void loadCredentials();
    void saveCredentials();
    void resetCredentials();
};

#endif